package leading;

import java.io.UnsupportedEncodingException;
import java.security.*;

public class MD5Test {
	public static String md5(String str){
		if(str == null){
			System.out.println("输入有误！！");
			return "";
		}
		String value = null;
		MessageDigest md5 = null;
		
		try {
			md5 = MessageDigest.getInstance("MD5");
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		sun.misc.BASE64Encoder baseEncoder = new sun.misc.BASE64Encoder();
		
		try {
			value = baseEncoder.encode(md5.digest(str.getBytes("utf-8")));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return value;
	}	 
	public static void main(String[] args) {
		System.out.println(md5("chewl"));
	}
}
